$(document).ready(function() {
	initSearchData();
});
var SEARCH_ISVERIFY = 1 //审核状态
var SEARCH_CREATE_TIME_START = 2; //建单开始时间
var SEARCH_CREATE_TIME_END = 4; //建单结束时间
var SEARCH_REGION_TYPE = 8; //区域类型
var SEARCH_REGION = 16; //区域名称
var SEARCH_HOUSE_NUMBER = 32; //摊位门牌号
var SEARCH_CHARGER = 64; //摊位负责人
var SEARCH_DEVICE_TYPE = 128; //设备类型
var SEARCH_DEVICE_NAME = 256; //设备名称
var SEARCH_DEVICE_RP = 512; //设备负责人
var SEARCH_LAST_SERVICE = 1024; //维护时间
var SEARCH_TENENT_NAME = 2048; //租户姓名
var SEARCH_IDCARD = 4096; //身份证号码
var SEARCH_TIME = 8192;//开始时间（事件部分用）
var SEARCH_DISTRIBUTION_DATE = 16384;//配送时间
var SEARCH_ORDER_NO = 32768;//合同编号查询
var SEARCH_STATE = 65536;//摊位状态查询
function buildSearchOptions(searchType, newdata) {
	var data = [{
		"name": "审核状态",
		"type": "ISVERIFY",
		"className": "easyui-combobox",
		"id": "input_ISVERIFY"
	}, {
		"name": "建单开始时间",
		"type": "CREATE_TIME_START",
		"className": "easyui-datebox",
		"id": "search_begin_time"
	}, {
		"name": "建单结束时间",
		"type": "CREATE_TIME_END",
		"className": "easyui-datebox",
		"id": "search_end_time"
	}, {
		"name": "区域类型",
		"type": "REGION_TYPE",
		"className": "easyui-combobox",
		"id": "input_REGION_TYPE"
	}, {
		"name": "区域名称",
		"type": "REGION_NAME",
		"className": "easyui-combobox",
		"id": "input_REGION_NAME"
	}, {
		"name": "摊位门牌号",
		"type": "HOUSE_NUMBER",
		"className": "easyui-textbox",
		"id": "input_HOUSE_NUMBER"
	}, {
		"name": "摊位负责人",
		"type": "CHARGER",
		"className": "easyui-textbox",
		"id": "input_CHARGER"
	}, {
		"name": "设备类型",
		"type": "DEVICE_TYPE",
		"className": "easyui-combobox",
		"id": "input_DEVICE_TYPE"
	}, {
		"name": "设备名称",
		"type": "NAME",
		"className": "easyui-combobox",
		"id": "input_NAME"
	}, {
		"name": "设备负责人",
		"type": "DEVICE_RP",
		"className": "easyui-textbox",
		"id": "input_DEVICE_RP"
	}, {
		"name": "维修时间",
		"type": "LAST_SERVICE",
		"className": "easyui-datebox",
		"id": "input_LAST_SERVICE"
	}, {
		"name": "租户姓名",
		"type": "NAME",
		"className": "easyui-combobox",
		"id": "search_name"
	}, {
		"name": "身份证号码",
		"type": "IDCARD",
		"className": "easyui-textbox",
		"id": "search_idcard"
	},{
		"name": "开始时间",
		"type": "TIME",
		"className": "easyui-datebox",
		"id": "search_time"
	}, {
		"name": "配送时间",
		"type": "DISTRIBUTION_DATE",
		"className": "easyui-datebox",
		"id": "input_DISTRIBUTION_DATE"
	},
	{
		"name": "合同编号",
		"type": "ORDER_NO",
		"className": "easyui-textbox",
		"id": "input_ORDER_NO"
	},
	{
		"name": "摊位状态",
		"type": "STATE",
		"className": "easyui-combobox",
		"id": "input_STATE"
	},
	];
	var content = "";
	var s;
	for(var i = 0; i < data.length; i++) {
		s = searchType & (1 << i);
		if(s != 0) {
			content += "<td>" + data[i].name + "</td><td><input class=\"" + data[i].className + "\" name=\"" + data[i].type + "\" id=\"" + data[i].id + "\"/></td>";
		}
	}
	if(newdata.length > 0) {
		for(var i = 0; i < newdata.length; i++) {
			content += "<td>" + newdata[i].name + "</td><td><input class=\"" + newdata[i].className + "\" name=\"" + newdata[i].type + "\" id=\"" + newdata[i].id + "\"/></td>";
		}
	}
	var contain = "<div id=\"p\" class=\"easyui-panel\" title=\"查询\" style=\"width:100%;height:100%;\"><table cellspacing=\"4\" style=\"margin-top: 10px;\"><tr>" + content;
	contain += "<td><a href=\"#\" class=\"easyui-linkbutton\" onclick=\"doSearch()\" data-options=\"iconCls:'icon-search'\" style=\"width:80px;\">查询</a></td></tr></table></div>";
	return contain;
}

function initSearchData() {
	if($("#input_REGION_TYPE") != undefined) {
		$('#input_REGION_TYPE').combobox({
			valueField: 'NAME',
			textField: 'NAME',
			panelHeight: 'auto',
			mode: 'remote',
			method: 'get',
			url: RemoteLinkAddress + "/market/regiontype/listall.do",
		});
	}
	if($("#input_REGION_NAME") != undefined) {
		$('#input_REGION_NAME').combobox({
			valueField: 'NAME',
			textField: 'NAME',
			panelHeight: 'auto',
			mode: 'remote',
			method: 'get',
			url: RemoteLinkAddress + '/market/region/listall.do',
		});
	}
	if($("#input_DEVICE_TYPE") != undefined) {
		$("#input_DEVICE_TYPE").combobox({
			valueField: 'NAME',
			textField: 'NAME',
			panelHeight: 'auto',
			mode: 'remote',
			method: 'get',
			url: RemoteLinkAddress + '/market/devicetype/listall.do'
		});
	}
	if($("#input_ISVERIFY") != undefined) {
		$("#input_ISVERIFY").combobox({
			panelHeight: '50px',
			valueField: 'value',
			textField: 'text',
			data: [{
				value: '0',
				text: '未审核'
			}, {
				value: '1',
				text: '已审核'
			}]
		});
	}
	
	if($("#input_STATE") != undefined) {
		$("#input_STATE").combobox({
			panelHeight: 'auto',
			valueField: 'value',
			textField: 'text',
			data: [{
				value: '未开始',
				text: '未开始'
			}, {
				value: '在租',
				text: '在租'
			},
			{
				value: '到期',
				text: '到期'
			},
			{
				value: '全部',
				text: '全部'
			},
			]
		});
	}
}

function processSearchCondition() {
	if($("#div_search") == undefined) {
		console.log("请检查ID为div_search是否存在");
		return "";
	}
	var searchCondition = "";
	$("#div_search input[name]").each(function(index) {
		if($(this).val().trim().length != 0) {
			if(searchCondition == "") {
				searchCondition = $(this).attr("name") + "=" + $(this).val().trim();
			} else {
				searchCondition += "&" + $(this).attr("name") + "=" + $(this).val().trim();
			}
		}
	});
	return searchCondition;
}